home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1999 January / EnigmA AMIGA RUN 33 (1999)(G.R. Edizioni)(IT)[!][issue 1999-01].iso / earcd / faq / computer-lang / forth-faq / part1.z / part1
Internet Message Format  |  1999-01-01  |  20KB

  1. Path: senator-bedfellow.mit.edu!bloom-beacon.mit.edu!cam-news-feed5.bbnplanet.com!cam-news-hub1.bbnplanet.com!cpk-news-hub1.bbnplanet.com!news.bbnplanet.com!Supernews73!supernews.com!Supernews69!www.taygeta.com!jon
  2. From: jon@taygeta.com (J. D. Verne)
  3. Newsgroups: comp.lang.forth,comp.answers,news.answers
  4. Subject: comp.lang.forth FAQ: General Information (1 of 6)
  5. Supersedes: <forth-faq-1-905049188@taygeta.com>
  6. Followup-To: comp.lang.forth
  7. Date: 2 Oct 1998 11:43:47 GMT
  8. Organization: The Forth Interest Group
  9. Lines: 499
  10. Approved: news-answers-request@MIT.EDU
  11. Distribution: world
  12. Expires: 06 Nov 98 11:44:01
  13. Message-ID: <forth-faq-1-907328641@taygeta.com>
  14. Reply-To: faq@forth.org (FAQ maintainers list)
  15. NNTP-Posting-Host: 206.55.232.69
  16. X-Trace: 907328627 6BUII4S.ME845CE37C usenet52.supernews.com
  17. X-Complaints-To: newsabuse@supernews.com
  18. Keywords: FAQ FORTH FIG
  19. Originator: jon@www.taygeta.com
  20. Xref: senator-bedfellow.mit.edu comp.lang.forth:41656 comp.answers:33296 news.answers:141269
  21.  
  22. Posted-By: auto-faq 3.3 (Perl 5.004)
  23. Archive-name: computer-lang/forth-faq/part1
  24. Posting-Frequency: Monthly.  A how-to-find-the-FAQ article is posted weekly.
  25.  
  26.   comp.lang.forth Frequently Asked Questions (1/6): Gen-
  27.   eral/Misc
  28.   M. Anton Ertl, anton@mips.complang.tuwien.ac.at
  29.  
  30.   ____________________________________________________________
  31.  
  32.   Table of Contents:
  33.  
  34.   1.      Acknowledgements
  35.  
  36.   2.      comp.lang.forth FAQs
  37.  
  38.   3.      General Questions
  39.  
  40.   3.1.    What is Forth?
  41.  
  42.   3.2.    Where does the name Forth come from?
  43.  
  44.   3.3.    Why and where is Forth used?
  45.  
  46.   3.4.    Hang on, isn't Forth out of date now?
  47.  
  48.   3.5.    Is Forth faster or smaller than C?
  49.  
  50.   3.6.    What language standards exist for Forth?
  51.  
  52.   3.7.    What is an RFI?
  53.  
  54.   3.8.    Are there Coding Standards for Forth?
  55.  
  56.   3.9.    I have trouble managing the stack. Should I use global
  57.   VARIABLEs?
  58.  
  59.   3.10.   What is the Forth Interest Group?
  60.  
  61.   4.      Flame baits
  62.  
  63.   4.1.    Commercial vs. free Forth systems
  64.  
  65.   4.2.    Free Forth systems are bad for Forth.
  66.  
  67.   4.3.    Blocks vs. files
  68.  
  69.   4.4.    LOCALS|
  70.  
  71.   5.      Miscellaneous
  72.  
  73.   5.1.    Where can I find a C-to-Forth compiler?
  74.  
  75.   5.2.    Where can I find a Forth-to-C compiler?
  76.  
  77.   5.3.    RECORDS in Forth?
  78.  
  79.   5.4.    Why does THEN finish an IF structure?
  80.  
  81.   5.5.    What is threaded code? What are the differences between the
  82.   different threading techniques?
  83.  
  84.   5.6.    Has anyone written a Forth which compiles to Java bytecode?
  85.  
  86.   5.7.    What about translating Java bytecode to Forth?
  87.   ______________________________________________________________________
  88.  
  89.   1.  Acknowledgements
  90.  
  91.   This FAQ is based on previous work by Gregory Haverkamp, J. D. Verne,
  92.   and Bradford J. Rodriguez.
  93.  
  94.   2.  comp.lang.forth FAQs
  95.  
  96.   The comp.lang.forth FAQ is published in six parts, corresponding to
  97.   these six sections.  This part is the General/Misc FAQ, where the
  98.   questions not covered in the other FAQs are answered. The six parts
  99.   are:
  100.  
  101.   o  General questions <http://www.complang.tuwien.ac.at/forth/faq/faq-
  102.      general.html>
  103.  
  104.   o  Online resources <http://www.complang.tuwien.ac.at/forth/forl.html>
  105.  
  106.   o  Forth vendors <http://www.faqs.org/faqs/computer-lang/forth-
  107.      faq/part3/>
  108.  
  109.   o  Forth systems <http://www.faqs.org/faqs/computer-lang/forth-
  110.      faq/part4/preamble.html>
  111.  
  112.   o  Books, periodicals, tutorials <http://www.faqs.org/faqs/computer-
  113.      lang/forth-faq/part5/>
  114.  
  115.   o  Forth groups & organizations <http://www.faqs.org/faqs/computer-
  116.      lang/forth-faq/part6/>
  117.  
  118.      You can get the text versions of these FAQs at
  119.      <ftp://ftp.forth.org/pub/Forth/FAQ/>.
  120.  
  121.   These FAQs are intended to be a brief overview of the tools and
  122.   information available for the new FORTHer.  For a historical
  123.   reference, programming paradigms, and deep technical information try
  124.   some of the listed references.  For general questions on the Usenet,
  125.   or the methods used to get this information, try these other Usenet
  126.   groups:
  127.  
  128.   o  news.announce.newusers
  129.  
  130.   o  news.newusers.questions
  131.  
  132.   o  news.announce.important
  133.  
  134.   3.  General Questions
  135.  
  136.   3.1.  What is Forth?
  137.  
  138.   Forth is a stack-based, extensible language without type-checking.  It
  139.   is probably best known for its "reverse Polish" (postfix) arithmetic
  140.   notation, familiar to users of Hewlett-Packard calculators: to add two
  141.   numbers in Forth, you would type  3 5 +  instead of 3+5.  The
  142.   fundamental program unit in Forth is the "word": a named data item,
  143.   subroutine, or operator. Programming in Forth consists of defining new
  144.   words in terms of existing ones.  The Forth statement
  145.  
  146.   ______________________________________________________________________
  147.   : SQUARED  DUP * ;
  148.   ______________________________________________________________________
  149.  
  150.   defines a new word SQUARED whose function is to square a number (mul-
  151.   tiply it by itself).  Since the entire language structure is embodied
  152.   in words, the application programmer can "extend" Forth to add new
  153.   operators, program constructs, or data types at will.  The Forth
  154.   "core" includes operators for integers, addresses, characters, and
  155.   Boolean values; string and floating-point operators may be optionally
  156.   added.
  157.  
  158.   3.2.  Where does the name Forth come from?
  159.  
  160.        The name FORTH was intended to suggest software for the
  161.        fourth (next) generation computers, which Moore saw as being
  162.        characterized by distributed small computers.  The operating
  163.        system he used at the time restricted file names to five
  164.        characters, so the "U" was discarded.  FORTH was spelled in
  165.        upper case until the late 70's because of the prevalence of
  166.        of upper-case-only I/O devices.  The name "Forth" was gener-
  167.        ally adopted when lower case became widely available,
  168.        because the word was not an acronym.
  169.  
  170.   Rather, Colbourn, and Moore: The Evolution of Forth
  171.   <http://www.forth.com/Content/History/History1.htm>, in: History of
  172.   Programming Languages (HOPL-II), ACM Press/Addison-Wesley 1996.
  173.  
  174.   Note: Forth is not a 4GL (language for programming database
  175.   applications).
  176.  
  177.   3.3.  Why and where is Forth used?
  178.  
  179.   Although invented in 1970, Forth became widely known with the advent
  180.   of personal computers, where its high performance and economy of
  181.   memory were attractive.  These advantages still make Forth popular in
  182.   embedded microcontroller systems, in locations ranging from the Space
  183.   Shuttle to the bar-code reader used by your Federal Express driver.
  184.   Forth's interactive nature streamlines the test and development of new
  185.   hardware. Incremental development, a fast program-debug cycle, full
  186.   interactive access to any level of the program, and the ability to
  187.   work at a high "level of abstraction," all contribute to Forth's
  188.   reputation for very high programmer productivity.  These, plus the
  189.   flexibility and malleability of the language, are the reasons most
  190.   cited for choosing Forth for embedded systems.
  191.  
  192.   3.4.  Hang on, isn't Forth out of date now?
  193.  
  194.   One of the best answers came from Brad Rodriguez
  195.   <mailto:bj@forth.org>. You can find the full version at
  196.   <http://www.complang.tuwien.ac.at/forth/faq/why-forth>. In short,
  197.   Forth's advantages are that it's comprehensible, small, interactive,
  198.   fast, extensible, and makes it easy to work at a high level of
  199.   abstraction.
  200.  
  201.   BTW, this question came from someone comparing a 10+ year old Forth
  202.   system with the latest version of Borland C++. His system was really
  203.   out of date, but also with respect to current Forth systems.
  204.   3.5.  Is Forth faster or smaller than C?
  205.  
  206.   Not in itself. I.e., if you translate a C program literally into
  207.   Forth, you will see a slow-down (e.g., a factor 4-8 with Gforth, a
  208.   threaded-code system; for typical native-code systems you will see a
  209.   factor of 1-3). Similarly, there is no inherent size advantage in
  210.   Forth. For details see
  211.   <http://www.complang.tuwien.ac.at/forth/performance.html>.
  212.  
  213.   However, there are many reports of cases where Forth programs beat
  214.   others in size and/or speed. My guess is that the added flexibility of
  215.   Forth helps programmers produce faster and/or smaller programs.
  216.  
  217.   3.6.  What language standards exist for Forth?
  218.  
  219.   An American National Standard for Forth, ANSI X3.215-1994, is accepted
  220.   worldwide as the definitive Forth standard.  ("ANS Forth")
  221.  
  222.   IEEE Standard 1275-1994, the "Open Firmware" standard, is a Forth
  223.   derivative which has been adopted by Sun Microsystems, HP, Apple, IBM,
  224.   and others as the official language for writing bootstrap and driver
  225.   firmware. See  <http://playground.sun.com/1275/home.html>.
  226.  
  227.   Prior Forth standards include the Forth-83 Standard and the Forth-79
  228.   Standard issued by the Forth Standards Team.  The earlier FIG-Forth,
  229.   while never formally offered as such, was a de facto "standard" for
  230.   some years.
  231.  
  232.   "FORTH STANDARDS  Published standards since 1978 are Forth 79 and
  233.   Forth 83 from the Forth Standard Team, and ANS Forth - document
  234.   X3.215-1994 - by the X3J14 Technical Committee.  The most recent
  235.   standard, ANS Forth, defines a set of core words and some optional
  236.   extensions and takes care to allow great freedom in how these words
  237.   are implemented.  The range of hardware which can support an ANS Forth
  238.   Standard System is far wider than any previous Forth standard and
  239.   probably wider than any programming language standard ever. See web
  240.   page  <http://ftp.uu.net/vendor/minerva/uathena.htm> for latest
  241.   details. Copies of the standard cost $193, but the final draft of ANS
  242.   Forth is free and available (subject to copyright restrictions) via
  243.   ftp..." --Chris Jakeman, apvpeter.demon.co.uk
  244.  
  245.   The (un)official ANS Forth document is available in various formats at
  246.   <http://www.taygeta.com/forthlit.html> and at
  247.   <ftp://ftp.uu.net/vendor/minerva/x3j14/>. The format I like best is
  248.   the HTML version <http://www.taygeta.com/forth/dpans.html>.
  249.  
  250.   To get yourself on the ANS-Forth mailing list, consult the various
  251.   README files at  <ftp://ftp.uu.net/vendor/minerva/x3j14/>.
  252.  
  253.   Two unofficial test suites are available for checking conformance to
  254.   the ANS Standard Forth:
  255.  
  256.   o  John Hayes has written a test suite to test ANS Standard Systems
  257.      (available through  <http://www.taygeta.com/forth.html>).
  258.  
  259.   o  JET Thomas has written a test suite to test ANS Standard Programs:
  260.      <ftp://ftp.forth.org/pub/Forth/ANS/stand4th.zip>
  261.  
  262.   3.7.  What is an RFI?
  263.  
  264.   A Request For Interpretation. If you find something in the standard
  265.   document ambiguous or unclear, you can make an RFI, and the TC
  266.   (technical committee), that produced the standard, will work out a
  267.   clarification. You can make an RFI by mailing it to greg@minerva.com
  268.   and labeling it as RFI. The answers to earlier RFIs are available at
  269.   ftp://ftp.uu.net/vendor/minerva/x3j14/queries/. They are also
  270.   integrated in the HTML version of the standard
  271.   <http://www.taygeta.com/forth/dpans.html>.
  272.  
  273.   3.8.  Are there Coding Standards for Forth?
  274.  
  275.   Leo Brodie's book Thinking Forth gives some advice; a short excerpt is
  276.   now available online <http://www.forth.org/forth_style.html>. Forth
  277.   shops have rules for their coding. Paul Bennet has published those of
  278.   his company; you can find them on
  279.   <http://www.forth.org/forth_coding.html>.
  280.  
  281.   3.9.  I have trouble managing the stack. Should I use global VARI-
  282.   ABLEs?
  283.  
  284.   No. There are better alternatives:
  285.  
  286.   o  Keep on trying to use the stack. Reorganize (refactor) your words.
  287.      One day you will get the knack for it. Elizabeth Rather
  288.      <mailto:erather@forth.com> writes:
  289.  
  290.        The basic skill required for comfortable, efficient Forth
  291.        programming is good stack management.  It's hard for newcom-
  292.        ers to learn, since it isn't a skill required in other lan-
  293.        guages, which all require the use of variables for practi-
  294.        cally everything.  Having taught literally hundreds of
  295.        courses over the last 25 years, I've seen newcomers wrestle
  296.        with this, and have developed exercises (similar to those in
  297.        Starting Forth) to help.  It seems to be a skill rather like
  298.        riding a bicycle: wobbly & scary at first, then suddenly a
  299.        "switch is thrown" in the brain and it seems comfortable and
  300.        natural ever after.
  301.  
  302.   o  Use the return stack.
  303.  
  304.   o  Use locals.
  305.  
  306.   o  Use data structures in memory, and pass pointers to it on the
  307.      stack.
  308.  
  309.   o  One area that has been mentioned often as troublemaker is graphics
  310.      programming. Take a look at how Postscript handles this: They do
  311.      indeed have a global state to avoid stack management problems, but
  312.      you can access this state only through certain words.
  313.  
  314.   3.10.  What is the Forth Interest Group?
  315.  
  316.   The Forth Interest Group "FIG" was formed in 1978 to disseminate
  317.   information and popularize the Forth language, and it remains the
  318.   premier organization for professional Forth programmers.  FIG
  319.   maintains a Web page at  <http://www.forth.org/forth.html>, with a
  320.   more complete introduction to the Forth language, and links to the Web
  321.   pages of many Forth vendors.
  322.   4.  Flame baits
  323.  
  324.   Some statements spawn long and heated discussions where the
  325.   participants repeat their positions and ignore the arguments of the
  326.   other side (flame wars). You may want to avoid such statements.
  327.  
  328.   Here, I present some regularly appearing flame baits and the positions
  329.   you will read (so you don't have to start a flame war to learn them).
  330.  
  331.   4.1.  Commercial vs. free Forth systems
  332.  
  333.   "You get what you pay for. With a commercial Forth you get commercial
  334.   documentation and support. We need commercial Forth systems or Forth
  335.   will die."
  336.  
  337.   "I have had good experiences with free Forths. I cannot afford a
  338.   commercial Forth system. I want source code (some commercial vendors
  339.   don't provide it for the whole system). Examples of bad support from
  340.   commercial software vendors. Without free Forth systems Forth will
  341.   die."
  342.  
  343.   4.2.  Free Forth systems are bad for Forth.
  344.  
  345.   "Anyone can write a bad Forth and give it away without documentation
  346.   or support; after trying such a system, nobody wants to work with
  347.   Forth anymore. Free Forths give Forth a bad name. Free Forths take
  348.   business away from the vendors."
  349.  
  350.   "Many people learned Forth with fig-Forth. There are good free Forths.
  351.   Most successful languages started with (and still have) free
  352.   implementations. Languages without free implementations (like Ada,
  353.   Eiffel and Miranda) are not very popular."
  354.  
  355.   4.3.  Blocks vs. files
  356.  
  357.   The discussions on this topic are much cooler since Mike Haas has
  358.   dropped from comp.lang.forth.
  359.  
  360.   "Everyone is using files and all third-party tools are designed for
  361.   files. Files waste less space. Blocks lead to horizontal, unreadable
  362.   code. Blocks make Forth ridiculous."
  363.  
  364.   "We are not always working under an operating system, so on some
  365.   machines we don't have files. We have very nice block editors and
  366.   other tools and coding standards for working with blocks (e.g., shadow
  367.   screens)."
  368.  
  369.   4.4.  LOCALS|
  370.  
  371.   Everyone who mentions using LOCALS| gets the following flame from me:
  372.  
  373.   LOCALS| is bad because the locals are ordered contrary to the stack
  374.   comment convention. I.e.:
  375.  
  376.   ______________________________________________________________________
  377.   : foo ( you can read this -- ... )
  378.    LOCALS| this read can you | ... ;
  379.   ______________________________________________________________________
  380.  
  381.   The following locals syntax is better and widely used:
  382.  
  383.   ______________________________________________________________________
  384.   : foo { you can read this -- ... }
  385.    ... ;
  386.   ______________________________________________________________________
  387.  
  388.   You can find an implementation of this syntax in ANS Forth at
  389.   <http://www.complang.tuwien.ac.at/forth/anslocal.fs>
  390.  
  391.   5.  Miscellaneous
  392.  
  393.   5.1.  Where can I find a C-to-Forth compiler?
  394.  
  395.   There have been roumors about such a compiler at Harris (for the RTX
  396.   chip) and elsewhere. The most concrete answer to this question has
  397.   come from Stephen Pelc (sfp@mpeltd.demon.co.uk):
  398.  
  399.   MPE has produced a C to stack-machine compiler. This generates tokens
  400.   for a 2-stack virtual machine. The code quality is such that the token
  401.   space used by compiled programs is better than that of the commercial
  402.   C compilers we have tested against. This a consequence of the virtual
  403.   machine design.  However, to achieve this the virtual machine design
  404.   has local variable support.
  405.  
  406.   The tokens can then be back end interpreted, or translated to a Forth
  407.   system. The translater can be written in high level Forth, and is
  408.   largely portable, except for the target architecture sections.
  409.  
  410.   These are not shareware tools, and were written to support a portable
  411.   binary system.
  412.  
  413.   5.2.  Where can I find a Forth-to-C compiler?
  414.  
  415.   An unsupported prototype Forth-to-C compiler is available at
  416.   <http://www.complang.tuwien.ac.at/forth/forth2c.tar.gz>. It is
  417.   described in the EuroForth'95 paper
  418.   <http://www.complang.tuwien.ac.at/papers/ertl&maierhofer95.ps.gz>.
  419.   Another Forth-to-C compiler is supplied with Rob Chapman's
  420.   <mailto:rc@compusmart.ab.ca> Timbre
  421.   <http://www.compusmart.ab.ca/rc/Timbre/timbre.htm> system.
  422.  
  423.   5.3.  RECORDS in Forth?
  424.  
  425.   Many packages for data structuring facilities like Pascal's RECORDs
  426.   and C's structs have been posted. E.g., the structures of the Forth
  427.   Scientific Library ( <http://www.taygeta.com/fsl/fsl_structs.html>) or
  428.   the structures supplied with Gforth
  429.   <http://www.complang.tuwien.ac.at/forth/struct.fs>.
  430.  
  431.   5.4.  Why does THEN finish an IF structure?
  432.  
  433.   Some people find the way THEN is used in Forth unnatural, others do
  434.   not.
  435.  
  436.   According to Webster's New Encyclopedic Dictionary, then" (adv.) has
  437.   the following meanings:
  438.  
  439.        2b: following next after in order ... 3d: as a necessary
  440.        consequence (if you were there, then you saw them).
  441.  
  442.   Forth's THEN has the meaning 2b, whereas THEN in Pascal and other pro-
  443.   gramming languages has the meaning 3d.
  444.  
  445.   If you don't like to use THEN in this way, you can easily define ENDIF
  446.   as a replacement:
  447.  
  448.   ______________________________________________________________________
  449.   : ENDIF  POSTPONE THEN ; IMMEDIATE
  450.   ______________________________________________________________________
  451.  
  452.   5.5.  What is threaded code? What are the differences between the dif-
  453.   ferent threading techniques?
  454.  
  455.   Threaded code is a way of implementing virtual machine interpreters.
  456.   You can find a more in-depth explanation at
  457.   <http://www.complang.tuwien.ac.at/forth/threaded-code.html>.
  458.  
  459.   5.6.  Has anyone written a Forth which compiles to Java bytecode?
  460.  
  461.   Paul Curtis <mailto:paul.curtis@ra-ltd.demon.co.uk> writes:
  462.  
  463.   The JVM, although a stack machine, can't really be used to compile
  464.   Forth efficiently.  Why?  Well, there are a number of reasons:
  465.  
  466.   o  The maximum stack depth of a called method must be known in
  467.      advance. JVM Spec, p. 111
  468.  
  469.   o  JVM methods can only return a single object to the caller.  Thus, a
  470.      stack effect ( n1 n2 -- n3 n4 ) just isn't possible.
  471.  
  472.   o  There is no direct support for unsigned quantities.
  473.  
  474.   o  CATCH and THROW can't be resolved easily; you need to catch
  475.      exceptions using exception tables.  This doesn't match Forth's
  476.      model too well.  JVM Spec, p. 112
  477.  
  478.   o  You'd need to extend Forth to generate the attributes required for
  479.      Java methods.
  480.  
  481.   o  There is no such thing as pointer arithmetic.
  482.  
  483.   o  You can't take one thing on the stack and recast it to another
  484.      type.
  485.  
  486.   o  You can't manufacture objects out of raw bytes.  This is a security
  487.      issue.
  488.  
  489.   o  There is no support for the return stack.
  490.  
  491.   That said, it is possible to write something Forth-like using JVM
  492.   bytecodes, but you can't use the JVM stack to implement the Forth
  493.   stack.  ...
  494.  
  495.   If you're serious, try getting Jasmin and programming directly on the
  496.   JVM.
  497.  
  498.   5.7.  What about translating Java bytecode to Forth?
  499.  
  500.   Some of the non-trivial pieces in translating JavaVM to Forth, that we
  501.   have identified, are:
  502.  
  503.   o  garbage collection
  504.  
  505.   o  threads
  506.  
  507.   o  control structures (branches->ANS Forth's seven universal control
  508.      structure words)
  509.  
  510.   o  exceptions
  511.  
  512.   o  subroutines (JavaVM does not specify that a subroutine returns to
  513.      its caller)
  514.  
  515.   o  JavaVM makes the same mistake as Forth standards up to Forth-83: It
  516.      specifies type sizes (e.g., a JavaVM int is always 32-bit). A few
  517.      operators have to be added to support this.
  518.  
  519.   o  The native libraries (without them JavaVM can do nothing).
  520.  
  521.